package com.yuyou.tas.gateway.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;

public class requestLog {

	private String messageSn;
	
	private Long traceId;
	
	private String uri;
	
	private Long principal;
	
	private Map<String, String[]> params;
	
	private String resp;

	
	
	public String getMessageSn() {
		return messageSn;
	}

	public void setMessageSn(String messageSn) {
		this.messageSn = messageSn;
	}

	public Long getTraceId() {
		return traceId;
	}

	public void setTraceId(Long traceId) {
		this.traceId = traceId;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public Long getPrincipal() {
		return principal;
	}

	public void setPrincipal(Long principal) {
		this.principal = principal;
	}

	public Map<String, String[]> getParams() {
		return params;
	}

	public void setParams(Map<String, String[]> params) {
		this.params = params;
	}

	public String getResp() {
		return resp;
	}

	public void setResp(String resp) {
		this.resp = resp;
	}
	
	
	public String toStringLog(){	
		StringBuilder sb=new StringBuilder();
		sb.append("traceId:"+traceId+";");
		sb.append("uri:"+uri+";");
		sb.append("params:"+toEqualString(params,',')+";");
		sb.append("principal:"+principal+";");		
		sb.append("resp:"+resp.replace("\n", "").replace("\t", "")+";");	
		return sb.toString();
	}
	
    public static String toEqualString(Map<?, ?> map, char separator) {
        List<String> result = new ArrayList<>();
        map.entrySet().parallelStream().reduce(result, (first, second)->{
            first.add(second.getKey() + "=" + second.getValue());
            return first;
        }, (first, second)->{
            if (first == second) {
                return first;
            }
            first.addAll(second);
            return first;
        });

        return StringUtils.join(result, separator);
    }
        
}
